package ${package.ServiceImpl};

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import com.wsd.jing.request.CommonRequest;
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import com.wsd.jing.utils.SortUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.tom.com
 *
 * @author ${author}
 * @version 1.0.0
 * @projectName: ${project}
 * @packageName: ${package.ServiceImpl}
 * @className: ${table.serviceImplName}
<#assign entityName = "">
<#if (table.comment?? && table.comment != '')>
    <#if table.comment?ends_with("表")>
        <#assign entityName = table.comment?substring(0,table.comment?length-1)>
    <#else>
        <#assign entityName = table.comment>
    </#if>
<#else>
    <#assign entityName = table.entityName>
</#if>
 * @description: ${entityName!}服务实现类
 * @createDate ${date}
 * @copyright ${date} www.tom.com Inc. All rights reserved.
 */
@Service
@RequiredArgsConstructor
@Slf4j
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {

    private final ${table.mapperName} ${table.mapperName?uncap_first};

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean insert${entity}(${entity} ${entity?uncap_first}) {
        return this.save(${entity?uncap_first});
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean update${entity}(${entity} ${entity?uncap_first}) {
        return this.updateById(${entity?uncap_first});
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean delete${entity}(Integer id) {
        return this.removeById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean delete${entity}s(String ids) {
        List<String> idList = StrUtil.splitTrim(ids, ",");
        return this.removeByIds(idList);
    }

    @Override
    public ${entity} get${entity}(Integer id) {
        return this.getById(id);
    }

    @Override
    public List<${entity}> list${entity}s(CommonRequest commonRequest, ${entity} ${entity?uncap_first}) {
        QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
        // TODO 设置查询条件

        // 处理排序字段
        SortUtil.handleListSort(commonRequest, queryWrapper);
        return this.list(queryWrapper);
    }

    @Override
    public Map<String, Object> listPage${entity}s(CommonRequest commonRequest, ${entity} ${entity?uncap_first}) {
        Map<String, Object> resultMap = new HashMap<>(2);
        Page<${entity}> page = new Page<>(commonRequest.getPageNum(), commonRequest.getPageSize());
        QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
        // TODO 设置查询条件

        // 处理排序字段
        SortUtil.handlePageSort(commonRequest, page);
        IPage<${entity}> result = this.page(page, queryWrapper);
        resultMap.put("rows", result.getRecords());
        resultMap.put("total", result.getTotal());
        return resultMap;
    }
 }
</#if>
